#
# view.py -- main pygame display
# 
# author: Tom "Knio" Flanagan
#         knio@h4xn3t.net
#         theknio@gmail.com
#         irc.freenode.net - Knio - #python #pygame #py
#
# this file released under Public Domain
#


from constants import *
import object

class View:
    def __init__(self, battle):
        self.battle = battle
        self.size = self.battle.size
        self.border = 100
        self.offset = self.size + self.border
        self.screen = pygame.display.set_mode((int(self.offset*2), int(self.offset*2)))
	self.done = False
	self.dirty = [self.screen.get_rect()]
	self.objects = []
	self.clock = pygame.time.Clock()

    def event(self):
        for i in pygame.event.get():
            if i.type == QUIT:
                pygame.quit()
                self.done = True
                raise SystemExit
          
    def tick(self):
        self.clock.tick()
	self.event()
	self.render()

    def render(self):
        self.screen.fill((20,20,20))
        self.screen.fill((0,0,0),(self.border, self.border, self.size*2, self.size*2))
        self.info()
        for i in self.battle.objects:
            if not i.view: i.view = object.Object(self, i)
            i.view.tick()
        pygame.display.flip()

    def info(self):
        if not hasattr(self,'font'): self.font = pygame.font.Font(None, 14)
        self.screen.blit(self.font.render("fps:", 1, (255,255,255)), (10,10))
        self.screen.blit(self.font.render(str(self.clock.get_fps()), 1, (255,255,255)), (50,10))

        self.screen.blit(self.font.render("objects:", 1, (255,255,255)), (10,30))
        self.screen.blit(self.font.render(str(len(self.battle.objects)), 1, (255,255,255)), (50,30))
        
